import React from "react";
import {BaseComponent} from "fe-lib";
import {Input, Form, Radio} from "antd";
import formConfig from "shared/utils/formConfig";
import {isNullOrUndefined} from "shared/utils/stringKit";

const {Item} = Form;

class CrudForm extends BaseComponent {

  render() {
    const {form: {getFieldDecorator}} = this.props;
    return (
      <Form className="ant-form-auto">
        <Item
          {...formConfig.formItemLayout}
          label="名称"
          hasFeedback
        >
          {getFieldDecorator('name', {
            rules: [{required: true,},],
          })(
            <Input placeholder="请输入数据源名称"/>
          )}
        </Item>
        <Item
          {...formConfig.formItemLayout}
          label="类型"
          hasFeedback
        >
          {getFieldDecorator('type', {
            rules: [{required: true,}],
          })(
            <Radio.Group>
              <Radio value="fireBird">fireBird</Radio>
              <Radio value="sqlite">SQLite</Radio>
              <Radio value="mysql">MySQL</Radio>
            </Radio.Group>
          )}
        </Item>
        <Item
          {...formConfig.formItemLayout}
          label="驱动"
          hasFeedback
        >
          {getFieldDecorator('driverName', {
            rules: [{required: true,},],
          })(
            <Input placeholder="请输入数据库驱动"/>
          )}
        </Item>
        <Item
          {...formConfig.formItemLayout}
          label="用户名"
          hasFeedback
        >
          {getFieldDecorator('username', {
            rules: [{required: true,},],
          })(
            <Input placeholder="请输入用户名"/>
          )}
        </Item>
        <Item
          {...formConfig.formItemLayout}
          label="密码"
          hasFeedback
        >
          {getFieldDecorator('password', {
            rules: [{required: true,},],
          })(
            <Input placeholder="请输入密码"/>
          )}
        </Item>
        <Item
          {...formConfig.formItemLayout}
          label="URL"
          hasFeedback
        >
          {getFieldDecorator('url', {
            rules: [{required: true,},],
          })(
            <Input placeholder="请输入URL"/>
          )}
        </Item>
        <Item
          {...formConfig.formItemLayout}
          label="Schema"
          hasFeedback
        >
          {getFieldDecorator('schema', {
            rules: [{required: true,},],
          })(
            <Input placeholder="请输入Schema"/>
          )}
        </Item>
      </Form>
    );
  }
}

export default Form.create(formConfig.createOption)(CrudForm);
